import pandas as pd


# 读取Excel文件
def read_excel(file_path):
    df = pd.read_excel(file_path)
    return df


# 根据成绩生成评语
def generate_comment(score):
    if score >= 90:
        return "优秀！继续保持！"
    elif score >= 75:
        return "良好，继续努力！"
    elif score >= 60:
        return "及格，加油！"
    else:
        return "不及格，需要更加努力！"


# 保存结果
def save_results(output_file, results):
    df = pd.DataFrame(results)
    df.to_excel(output_file, index=False)
    print(f"结果已保存到 {output_file}")


def main():
    input_file = '学生成绩.xlsx'  # 输入的Excel文件
    output_file = '学生成绩和评语2.xlsx'
    df = read_excel(input_file)
    results = []
    for _, row in df.iterrows():
        row['成绩1'] = '221'
        row['成绩2'] = '222'
        row['成绩3'] = '223'
        score = row['成绩']
        row['评语'] = generate_comment(score)
        results.append(row)
    save_results(output_file, results)


# 入口函数
if __name__ == "__main__":
    main()
